package com.musiklegal;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;

public class LoginHandler extends DefaultHandler {
    
      private boolean status = false;
      private boolean desc = false;
      private boolean date = false;
      private boolean subid = false;
      private boolean balance = false;
      private boolean pass = false;
      private boolean user = false;
      private boolean in_startDate = false;
      private boolean in_currdate=false;
      private boolean in_fullname=false;
      private boolean in_social=false;
      private boolean in_fbid=false;
      private boolean in_twid=false,
      				  in_userid = false,
      				  in_picture = false;
      
      StringBuffer sb=new StringBuffer();
      
      private ParsedLoginDataSet myParsedLoginDataSet = new ParsedLoginDataSet();
      public ParsedLoginDataSet getParsedLoginData() {
            return this.myParsedLoginDataSet;
      }
      @Override
      public void startDocument() throws SAXException {
            this.myParsedLoginDataSet = new ParsedLoginDataSet();
      }
      @Override
      public void endDocument() throws SAXException {
            // Nothing to do
      }
      @Override
      public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
            if (localName.equals("reply")) {
                
            } 
             else if (localName.equals("description")) {
                  this.desc = true;
            }
            else if (localName.equals("desc"))
                this.desc = true;
            else if (localName.equals("subscription_id"))
                this.subid = true;
            else if (localName.equals("status"))
                this.status = true;
            else if (localName.equals("balance"))
                this.balance = true;
            else if (localName.equals("subscription_enddate"))
                this.date = true;
            else if (localName.equals("username"))
                this.user = true;
            else if (localName.equals("password"))
                this.pass = true;
            else if(localName.equals("subscription_startdate"))
            	in_startDate=true;
            else if(localName.equals("current_date"))
            	in_currdate=true;
            else if(localName.equals("start_date"))
            	in_startDate = true;
            else if(localName.equals("fullname"))
            	in_fullname = true;
            else if(localName.equals("socialnet"))
            	in_social = true;
            else if(localName.equals("facebook"))
            {
            	in_fbid = true;
            }
            else if(localName.equals("twitter"))
            {		
            	in_twid = true;
            }
            else if(localName.equals("end_date"))
            	date = true;
            else if(localName.equals("user_id"))
            	in_userid=true;
            else if(localName.equals("picture"))
            	in_picture = true;
      }
      @Override
      public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
            if (localName.equals("reply"))
            {}
            else if (localName.equals("description"))
                  this.desc = false;
            else if (localName.equals("desc"))
                this.desc = false;
            else if (localName.equals("subscription_id"))
                this.subid = false;
            else if (localName.equals("status"))
                this.status = false;
            else if (localName.equals("balance"))
                this.balance = false;
            else if (localName.equals("subscription_enddate"))
                this.date = false;
            else if (localName.equals("username"))
                this.user = false;
            else if (localName.equals("password"))
                this.pass = false;
            else if(localName.equals("subscription_startdate"))
            	in_startDate=false;
            else if(localName.equals("current_date"))
            	in_currdate =false;
            else if(localName.equals("start_date"))
            	in_startDate = false;
            else if(localName.equals("fullname"))
            	in_fullname = false;
            else if(localName.equals("socialnet"))
            	in_social = false;
            else if(localName.equals("facebook"))
            	in_fbid = false;
            else if(localName.equals("twitter"))
            	in_twid = false;
            else if(localName.equals("end_date"))
            	date = false;
            else if(localName.equals("user_id"))
            	in_userid=false;
            else if(localName.equals("picture"))
            	{
            	in_picture = false;
            		myParsedLoginDataSet.setProfpict(sb.toString());
            	}
            	
    
      }
      @Override
      public void characters(char ch[], int start, int length) {
            if (this.desc) 
            {
                  myParsedLoginDataSet.setExtractedString(new String(ch, start,length));
            }
            if (this.date)
            {
            	myParsedLoginDataSet.setDate(new String(ch, start,length));
            }
            if (this.status) 
            {
                  myParsedLoginDataSet.setStatus(new String(ch, start,length));
            }
            if (this.subid) 
            {
                  myParsedLoginDataSet.setSiD(new String(ch, start,length));
            }
            if (this.balance) 
            {
                  myParsedLoginDataSet.setBal(new String(ch, start,length));
            }
            if (this.user) 
            {
                  myParsedLoginDataSet.setUse(new String(ch, start,length));
            }
            if (this.pass) 
            {
                  myParsedLoginDataSet.setPas(new String(ch, start,length));
            }
            if(in_startDate)
            {
            	myParsedLoginDataSet.setStart(new String(ch,start,length));
            }
            if(in_currdate)
            {
            	myParsedLoginDataSet.setCurrDate(new String(ch,start,length));
            }
            
             if(in_startDate)
            	myParsedLoginDataSet.setStart(new String(ch,start,length));
             if(date)
            	 myParsedLoginDataSet.setDate(new String(ch,start,length));
             if(in_fullname)
            	 myParsedLoginDataSet.setFullName(new String(ch,start,length));
             if(in_fbid)
            	 myParsedLoginDataSet.setFB(new String(ch,start,length));
             if(in_twid)
            	 myParsedLoginDataSet.setTW(new String(ch,start,length));
             
             if(in_userid)
             	myParsedLoginDataSet.setUserId(new String(ch,start,length));
             if(in_picture)
             { 
            	 sb.append(new String(ch,start,length));
             }
      }
}